package com.jiantong.work.impl.service;

import com.google.common.base.Throwables;
import com.jiantong.work.impl.dao.ImmunizationDetectionDao;
import com.jiantong.work.impl.manager.ImmunizationDetectionManager;
import com.jiantong.work.model.ImmunizationDetection;
import com.jiantong.work.service.ImmunizationDetectionWriteService;
import io.terminus.boot.rpc.common.annotation.RpcProvider;
import io.terminus.common.model.Response;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * Created by maowenjie on 2017/3/14.
 *
 */
@Slf4j
@Service
@RpcProvider
public class ImmunizationDetectionWriteServiceImpl implements ImmunizationDetectionWriteService {

    private final ImmunizationDetectionManager immunizationDetectionManager;

    private final ImmunizationDetectionDao immunizationDetectionDao;
    @Autowired
    public ImmunizationDetectionWriteServiceImpl( ImmunizationDetectionManager immunizationDetectionManager,
                                                  ImmunizationDetectionDao immunizationDetectionDao) {

        this.immunizationDetectionManager = immunizationDetectionManager;
        this.immunizationDetectionDao=immunizationDetectionDao;
    }


    @Override
    public Response<Map<String,Object>> create(ImmunizationDetection immunizationDetection,Integer toStatus) {
        try {
            return Response.ok(immunizationDetectionManager.createImmunizationDetection(immunizationDetection,toStatus));
        }catch (Exception e){
            log.error("failed.to.create {},case:{}" ,immunizationDetection,Throwables.getStackTraceAsString(e));
            return Response.fail("immunization.detection.create.fail");
        }
    }

    @Override
    public Response<Map<String,Object>> update(ImmunizationDetection immunizationDetection,Integer toStatus) {
        try {
            return Response.ok(immunizationDetectionManager.updateImmunizationDetection(immunizationDetection,toStatus));
        }catch (Exception e){
            log.error("failed.to.update {},case:{}" ,immunizationDetection,Throwables.getStackTraceAsString(e));
            return Response.fail("immunization.detection.update.fail");
        }
    }

    @Override
    public Boolean update(ImmunizationDetection immunizationDetection) {
        return immunizationDetectionDao.update(immunizationDetection);
    }


}
